<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="com.stone.para.IConstant"%>
<%@ page import="com.stone.sys.pojo.TOrgan"%>
<%
	String contextPath = request.getContextPath();
	String bdzid = (String) request.getParameter("bdzid");
%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><%=IConstant.PROGRAEM_TITLE%></title>
        <link rel="stylesheet" href="<%=contextPath%>/ext3/resources/css/ext-all.css" type="text/css"   />
        <script src="<%=contextPath%>/ext3/adapter/ext/ext-base.js"></script>
        <script src="<%=contextPath%>/ext3/ext-all.js"></script>
        <style type="text/css">
        html { overflow-y: hidden; }        
        </style>
        <script language="javascript">
            Ext.BLANK_IMAGE_URL = '<%=contextPath%>/ext3/resources/images/default/s.gif';
            Ext.QuickTips.init();
            Ext.form.Field.prototype.msgTarget = 'qtip';
            var cpath = '<%=contextPath%>';		
			var treetitle = '<%=IConstant.PROGRAEM_TITLE2%>';			
		    var tree;
		    
		    var expflag = false;

		    String.prototype.endWith=function(str){
		    	if(str==null||str==""||this.length==0||str.length>this.length)
		    	return false;
		    	if(this.substring(this.length-str.length)==str)
		    	return true;
		    	else
		    	return false;
		    	return true;
		    	}
		   
		Ext.onReady(function(){
			
			var myloader =  new Ext.tree.TreeLoader({
	        		url : 'ddqx!getListExtTree.do?parentid=',
	        		listeners:{"beforeload":function(loader, node){
						loader.url ='ddqx!getListExtTree.do?bdzid=<%=bdzid%>&parentid=' + node.id ;
	        		}}
	        });

			this.tree = new Ext.tree.TreePanel({
				
	            id:"mytree",   
				renderTo : "tree",
                rootVisible:true,
				width : 300,   
                height : 480,
	            root : new Ext.tree.AsyncTreeNode({   
	        		id : "0", 
	        		draggable:false, 
	        		singleClickExpand:true, 
	        		text : treetitle,
	        		qtip:'100'
				}),   
				loader:myloader,
		        useArrows:true,
		        autoScroll:true,
		        animate:true,
				containerScroll:true

			})
			this.tree.root.expand();
			//this.tree.root.expandChildNodes();
			//tree.expandAll();
			this.tree.on({
				'click' : function(node){
					// 间隔的时候
					if (node.attributes.qtip!= undefined&&node.attributes.qtip=='s') {
						try {
								window.opener.document.frmM.elements["entity.sbmc"].value = node.text;
								if(node.parentNode.attributes.qtip=='间'){
								window.opener.document.frmM.elements["entity.dydj"].value = node.parentNode.parentNode.text;
								}else{
								window.opener.document.frmM.elements["entity.dydj"].value = node.parentNode.parentNode.parentNode.text;
								}									
								window.opener.document.frmM.elements["entity.sblx"].value = (node.id+"").split('@')[1];		
								//window.opener.document.frmM.elements["entity.sbid"].value = (node.id+"").split('@')[0];								
								window.close();
							} catch (e) {							
							//window.close();
							}
					}
				}
			});
			
		        /* 加载数据后操作 */
            	myloader.on("load", function(loader, node) { 
            			if (node.childNodes.length > 0  && expflag == false) {
            				for(var i =0;i<node.childNodes.length;i++) {
								if(!node.childNodes[i].text.endWith('站')) {
									node.childNodes[i].expand();
								} else {
									node.childNodes[i].expand();
									expflag = true;
									break;
								}
							}
            			}

                });

 	});
 		
 		
		
 		

		</script>
	</head>
	<body style="html { overflow-y: hidden; }">		
		<div id="tree" style="position:absolute;left:0px;top:25px;width:100%;height:100%;overflow:hidden;border:none"></div>
	</body>
</html>
